//
// Created by guo on 24-8-30.
//
#include "BBClient.h"
#include <thread>
#include <unistd.h>

int main(int argc, char** argv){
    if(argc < 2){
        std::cout << "need 2 args" << std::endl;
        return 0;
    }

    BBClient client{};
    client.connect("127.0.0.1",9999);
    std::this_thread::sleep_for(std::chrono::milliseconds(2000));

    std::thread t2([&](){
        int num = 0;
        while(1){
            if(atoi(argv[1]) == 0){
                client.set_blackboard("key1", std::to_string(num++));
                std::this_thread::sleep_for(std::chrono::milliseconds(1000));
            }else if(atoi(argv[1]) == 1){
                std::string value;
                if(client.get_blackboard("key1",value)){
                    std::cout << value << std::endl;
                }else{
                    std::cout << "get value failed!!!" << std::endl;
                }
                //std::this_thread::sleep_for(std::chrono::milliseconds(80));
            }else if(atoi(argv[1]) == 2){
                client.erase_blackboard("key1");
                break;
            }

        }

    });
    t2.join();

    return 0;
}